//基类
var app = angular.module("dj_app", ["route", "ngCordova", "override", "ngResource", "timer", "service"]);
app.filter('trustHtml', function ($sce) {
    return function (input) {
        return $sce.trustAsHtml(input);
    }
});
app.directive('scrollHeight', function ($window) {
    return {
        restrict: 'AE',
        link: function (scope, element, attr) {
            // element[0].style.height=($window.innerHeight-44-55-400)+'px';
            element[0].style.height = (500 - 44 - 270) + 'px';
        }
    }
});

app.run(["$ionicPlatform", "$rootScope", "$location", "$timeout", "$ionicHistory", "$cordovaToast", "$cordovaKeyboard", function ($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory, $cordovaToast, $cordovaKeyboard) {
    $ionicPlatform.ready(function () {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleLightContent();
        }
        //蒙版
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
    });

    //物理返回按钮控制&双击退出应用
    $ionicPlatform.registerBackButtonAction(function (e) {
        //判断处于哪个页面时双击退出
        if ($location.path() == "/login" || $location.path() == "/tab/home") {
            if ($rootScope.backButtonPressedOnceToExit) {
                ionic.Platform.exitApp();
            } else {
                $rootScope.backButtonPressedOnceToExit = true;
                $cordovaToast.showShortBottom("再按一次退出系统");
                setTimeout(function () {
                    $rootScope.backButtonPressedOnceToExit = false;
                }, 2000);
            }
        } else if ($ionicHistory.backView()) {
            if ($cordovaKeyboard.isVisible()) {
                $cordovaKeyboard.close();
            } else {
                $ionicHistory.goBack();
            }
        }
        else {
            $rootScope.backButtonPressedOnceToExit = true;
            $cordovaToast.showShortBottom("再按一次退出系统");
            setTimeout(function () {
                $rootScope.backButtonPressedOnceToExit = false;
            }, 2000);
        }
        e.preventDefault();
        return false;
    }, 101);
}]);
//全局变量
var user_info = {};
var exam_subject = {};
//用于获取每次修改后的生日
var birthDay = "";
//日期格式化 日期转字符串
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};
//一个月有多少天
Date.daysInMonth = function (year, month) {
    if (month == 1) {
        if (year % 4 == 0 && year % 100 != 0)
            return 29;
        else
            return 28;
    } else if ((month <= 6 && month % 2 == 0) || (month = 6 && month % 2 == 1))
        return 31;
    elseq
        return 30;
};
//设置访问路径
var getPath = {
    url:"http://shuyuan.itanggula.com:8080",
    name:"/itanggula-app"
}
//唐古拉书院
// localStorage.setItem("getPath",JSON.stringify(getPath));
var imgPath = {
    url:"http://admin.itanggula.com/",
    name:"/partybuilding"
}
// localStorage.setItem("imgPath",JSON.stringify(imgPath));
// app.config(function($httpProvider) {
//   $httpProvider.interceptors.push(function($rootScope) {
//     return {
//       request: function(config) {
//         $rootScope.$broadcast('loading:show')
//         return config
//       },
//       response: function(response) {
//         $rootScope.$broadcast('loading:hide')
//         return response
//       }
//     }
//   })
// });
//
// app.run(function($rootScope, $ionicLoading) {
//   $rootScope.$on('loading:show', function() {
//     $ionicLoading.show({
//       template: 'foo',
//       duration:3000
//     });
//   })
//
//   $rootScope.$on('loading:hide', function() {
//     $ionicLoading.hide();
//   })
// });
